import asyncio
from functools import wraps

queue = asyncio.Queue()
from typing import Any, Callable, Dict, List
from starlette.background import BackgroundTask
from starlette.requests import Request


class SignalHandler:

    def __init__(self):
        self._registry = {}

    def handlers(self):
        return self._registry

    def register(self, _func=None):
        def _wrap(func):
            if asyncio.iscoroutinefunction(func):
                self._register_handler(func)
            else:
                raise Exception("Signal infirmary_controller must be async")

            @wraps(func)
            def _wrapper(*args, **kwargs):
                return func(*args, **kwargs)

            return _wrapper

        if _func is None:
            return _wrap
        else:
            return _wrap(func=_func)

    def _register_handler(self, func):
        if func.__name__ not in self._registry:
            self._registry[func.__name__] = func
